import request from '../request';
import { ElMessage } from 'element-plus';
import { TEST_URL, TOKEN } from '@/constant';
import { getItem } from '@/utils/storage';

export const getList = async (searchForm) => {
  const data = await request.get('/pdf/list', {
    params: searchForm
  });
  return data.data;
};

/**
 * 删除文件
 * @returns null
 */
export const deletePdf = async (ids) => {
  const data = await request.delete(`/pdf/delete/${ids}`);
  if (data.code !== 100) ElMessage.success('删除文件成功');
};

export const download = async (id) => {
  const token = getItem(TOKEN);
  const tokenParam = token ? `Bearer ${token}` : "";
  window.open(`${TEST_URL}/pdf/download/${id}/?token=` + tokenParam)
}

export const preview = async (id) => {
  const token = getItem(TOKEN);
  const tokenParam = token ? `Bearer ${token}` : "";
  window.open(`${TEST_URL}/pdf/preview/${id}/?token=` + tokenParam)
}
